package com.example.mapper;

import com.example.domain.dto.PaperDTO;
import com.example.domain.po.Paper;
import com.example.domain.po.PaperAndQuestion;
import com.example.domain.po.Question;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PaperMapper {
    List<Paper> listByPage(String name);

    Integer addPaper(PaperDTO paperDTO);

    void addPaperAndQuestion(@Param("questions") List<PaperAndQuestion> questions,@Param("id") Integer id);

    @Select("select * from paper " +
            "where id=#{id} ")
    Paper getById(Integer id);

    @Delete("delete from paper " +
            "where id=#{id} ")
    void deleteById(Integer id);

    @Select("select question.* from paper_and_question " +
            "LEFT JOIN question on question.id=paper_and_question.question_id " +
            "where paper_id=#{id}")
    List<Question> PAQGetById(Integer id);

    void editPaper(PaperDTO paperDTO);

    @Delete("delete from paper_and_question " +
            "where paper_id=#{id} ")
    void deletePAQById(Integer id);
}
